let base = Module.findBaseAddress('MTPotal');

Interceptor.attach(ObjC.classes['DTRpcUtils']['+ compressGZip:'].implementation,
// Interceptor.attach(base.add(0x22AC34C),
    {
        onEnter(args){
            console.log('arg3', new ObjC.Object(args[2]));
            console.log('0x22AC34C',args[0],args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8]);
            // console.log(hexdump(args[0]));

            // console.log('arg1', hexdump(args[1], {length: args[2].toInt32()}));
            // console.log('arg2', hexdump(args[3], {length: args[4].toInt32()}));



        }
    }
)





// Interceptor.attach(base.add(0x22AD11C), {
//     onEnter(args){
//         console.log('0x22AD11C', args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8]);
//         console.log(hexdump(args[0]));
//
//     },
//     onLeave(ret){
//         console.log('0x22AD11C', ret);
//
//
//     }
// })
//
//

// Interceptor.attach(base.add(0xE1DEF0), {
//     onEnter(args) {
//         this.a1 = args[0]
//         this.a2 = args[1];
//         console.log('sub_E1DEF0', args[0], args[1], args[2], args[3], args[4], args[5]);
//         // console.log(Thread.backtrace(this.context, Backtracer.ACCURATE)
//         // .map(DebugSymbol.fromAddress).join('\n') + '\n')
//         var tid = Process.getCurrentThreadId();
//         this.tid = tid;
//         // Stalker.follow(tid, {
//         //     events: {
//         //         call: true, // CALL instructions: yes please
//         //         ret: false, // RET instructions
//         //         exec: false, // all instructions: not recommended as it's
//         //         block: false, // block executed: coarse execution trace
//         //         compile: false // block compiled: useful for coverage
//         //     },
//         //     transform: (iterator) => {
//         //         let instruction = iterator.next();
//         //         const startAddress = instruction.address;
//         //         var isAppCode = startAddress.compare(base.add(0xE1DEF0)) >= 0 && startAddress.compare(base.add(0xE1DEF0).add(10000)) === -1;
//         //         do {
//         //             if (isAppCode) {
//         //                 console.log(instruction.address.sub(base), instruction, '|', instruction.regsRead, '|', instruction.regsWritten);
//         //             }
//         //             iterator.keep();
//         //         } while ((instruction = iterator.next()) !== null);
//         //
//         //     }
//         // })
//
//
//     }, onLeave(ret) {
//
//
//         if (this.a2.equals(6)){
//             console.log('0xE1DEF0 ret', new ObjC.Object(ret));
//
//         }else if (this.a2.equals(5)){
//             console.log('0xE1DEF0 ret', hexdump(new ObjC.Object(ret).bytes()));
//
//         }
//         console.log(Thread.backtrace(this.context, Backtracer.ACCURATE)
//             .map(DebugSymbol.fromAddress).join('\n') + '\n')
//         Stalker.unfollow(this.tid);
//         Stalker.garbageCollect();
//     }
// })

let signFunc = ObjC.classes['NSUserDefaults']['- objectForKey:'].implementation;
Interceptor.attach(signFunc, {
    onEnter(args) {
        console.log('DTFrameworkInterface',new ObjC.Object(args[2]));
    },
    onLeave(ret) {
        console.log('objectForKey:', new ObjC.Object(ret))
    }
})

let signFunc2 = ObjC.classes['MPLiteSettingService']['+ registerDefaultsFromSettingsWithPlist:forBundle:'].implementation;
Interceptor.attach(signFunc2, {
    onEnter(args) {
        console.log('MPLiteSettingService');
    },
    onLeave(ret) {
        console.log('MPLiteSettingService:', new ObjC.Object(ret))
    }
})
let getModule = ObjC.classes['TrustedSignatureModule']['- computeTrustedSign:env:api:appid:auth:data:error:'].implementation;
Interceptor.attach(getModule, {
    onEnter(args) {
        console.log('TrustedSignatureModule', args[2],args[3], args[4],args[5], args[6])
        console.log('getModule',new ObjC.Object(args[2]));
        console.log('getModule',new ObjC.Object(args[3]));
        console.log('getModule',new ObjC.Object(args[4]));
        console.log('getModule',new ObjC.Object(args[5]));
        console.log('getModule',new ObjC.Object(args[6]));
        console.log('getModule',new ObjC.Object(args[7]));
        console.log('getModule',args[8]);
    },
    onLeave(ret) {
        console.log('ret', new ObjC.Object(ret))
    }
})


// let target = base.add(0xDD7DA0)
// console.log(Instruction.parse(target))
// Interceptor.attach(target, {
//     onEnter(args){
//         console.log('0EEDC7C', JSON.stringify(this.context))
//         console.log(hexdump(this.context.x0, {length:0xb0}))
//                 console.log(Thread.backtrace(this.context, Backtracer.ACCURATE)
//         .map(DebugSymbol.fromAddress).join('\n') + '\n')
//         // console.log(this.context.x9.add(0x14).readU16())
//         // console.log(this.context.fp.sub(0xb8).readU64().toString(16))
//         // console.log(hexdump(this.context.sp))
//     },
//     onLeave(ret){
//         console.log('0EF195C', ret, JSON.stringify(this.context))
//     }
// });